// NumericBox.cpp : implementation file
//

#include "stdafx.h"
#include "8085.h"
#include "NumericBox.h"
#include "GlobalFunctions.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CNumericBox dialog


CNumericBox::CNumericBox(CWnd* pParent /*=NULL*/)
	: CDialog(CNumericBox::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNumericBox)
	m_szNumber = _T("");
	m_szCaptionStr = _T("");
	//}}AFX_DATA_INIT
    SetCaption("Data");
}


void CNumericBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNumericBox)
	DDX_Text(pDX, IDC_GOTO_ADDRESS, m_szNumber);
	DDX_Text(pDX, IDC_CAPTION, m_szCaptionStr);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNumericBox, CDialog)
	//{{AFX_MSG_MAP(CNumericBox)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNumericBox message handlers

BOOL CNumericBox::DisplayNumericBox(int & nResult, int nLow, int nHigh, char * szInitialStr)
{
    m_szNumber= szInitialStr;
    while(1)
    {
        if(DoModal()!=IDOK) 
            return FALSE;
        static char str[256];
        int number;
        strncpy(str,m_szNumber,127);
        if(!::IsNumber(str,number))
        {
            MessageBox("Invalid Number ","Error");
            continue;
        }
        else
        {
            if(number>nHigh || number<nLow)  
            {
                sprintf(str,"Number should be within %d and %d",nLow,nHigh);
                MessageBox(str,"Error");
                continue;
            }
        }
        nResult = number;
        return TRUE;
    }
}

void CNumericBox::SetCaption(CString caption)
{
    m_szCaptionStr = caption;
}

CString & CNumericBox::GetCaption()
{
    return m_szCaptionStr;
}

